package cn.fuxi2022.accounts.register.controller;

import cn.fuxi2022.accounts.register.service.GroupRegisterService;
import cn.fuxi2022.model.empty.accounts.GroupRegister;
import cn.fuxi2022.model.resp.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/register")
public class GroupRegisterController {

    @Autowired
    private GroupRegisterService groupRegisterService;

    /**
     * 开始签到
     */
    @GetMapping("/start/{activityId}")
    public R startRegister(@PathVariable("activityId") String activityId) {
        // 开始签到逻辑
        // 将签到的二维码图片返回给签到
        return R.ok().data("registerImageUrl", groupRegisterService.startRegister(activityId));
    }


    /**
     * 根据活动ID获取已经签到的学生，供展示使用
     */
    @GetMapping("/studentList/{activityId}")
    public R getRegisterStudentList(@PathVariable("activityId") String activityId) {
        LambdaQueryWrapper<GroupRegister> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GroupRegister::getActivityId,activityId).orderByAsc(GroupRegister::getGmtCreate);
        return R.ok().data(groupRegisterService.list(wrapper));
    }
}
